# if we have a content object, use it to set the model and type
if ( !empty( $row['content'] ) ) {
+ if ( !( $row['content'] instanceof Content ) ) {
+ throw new MWException( '`content` field must contain a Content object.' );
+ }
+
// @todo when is that set? test with external store setup! check out insertOn() [dk]
if ( !empty( $row['text_id'] ) ) {
throw new MWException( "Text already stored in external store (id {$row['text_id']}), " .
// if we have a Content object, override mText and mContentModel
if ( !empty( $row['content'] ) ) {
- if ( !( $row['content'] instanceof Content ) ) {
- throw new MWException( '`content` field must contain a Content object.' );
- }
-
$handler = $this->getContentHandler();
$this->mContent = $row['content'];
];
yield 'with content' => [
[
- 'content' => ContentHandler::makeContent(
- 'hello world.',
- Title::newFromText( 'RevisionTest_testConstructWithContent' ),
- CONTENT_MODEL_JAVASCRIPT
- ),
+ 'content' => new JavaScriptContent( 'hellow world.' )
],
];
}
$this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() );
}
+ public function provideConstructThrowsExceptions() {
+ yield 'content and text_id both not empty' => [
+ [
+ 'content' => new WikitextContent( 'GOAT' ),
+ 'text_id' => 'someid',
+ ],
+ new MWException( "Text already stored in external store (id someid), " .
+ "can't serialize content object" )
+ ];
+ yield 'with bad content object (class)' => [
+ [ 'content' => new stdClass() ],
+ new MWException( '`content` field must contain a Content object.' )
+ ];
+ yield 'with bad content object (string)' => [
+ [ 'content' => 'ImAGoat' ],
+ new MWException( '`content` field must contain a Content object.' )
+ ];
+ yield 'bad row format' => [
+ 'imastring, not a row',
+ new MWException( 'Revision constructor passed invalid row format.' )
+ ];
+ }
+
+ /**
+ * @dataProvider provideConstructThrowsExceptions
+ */
+ public function testConstructThrowsExceptions( $rowArray, Exception $expectedException ) {
+ $this->setExpectedException(
+ get_class( $expectedException ),
+ $expectedException->getMessage(),
+ $expectedException->getCode()
+ );
+ new Revision( $rowArray );
+ }
+
public function provideGetRevisionText() {
yield 'Generic test' => [
'This is a goat of revision text.',